﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;

namespace Passwords.Biz
{
    public class EntityCollection<T>:Collection<T> where T : Entity
    {
        private Entity owner;
        private string collectionName;

        public EntityCollection(Entity owner, string name)
            : base()
        {
            this.owner = owner;
            this.collectionName = name;
        }

        public EntityCollection(Entity owner, string name, IList<T> list)
            : base(list)
        {
            this.owner = owner;
            this.collectionName = name;
        }

        protected override void ClearItems()
        {
            base.ClearItems();
            OnPropertyChanged();
        }

        protected override void InsertItem(int index, T item)
        {
            base.InsertItem(index, item);
            OnPropertyChanged();
        }

        protected override void RemoveItem(int index)
        {
            base.RemoveItem(index);
            OnPropertyChanged();
        }

        protected override void SetItem(int index, T item)
        {
            base.SetItem(index, item);
            OnPropertyChanged();
        }

        private void OnPropertyChanged()
        {
            owner.OnPropertyChanged(collectionName);
        }

    }
}
